package operation;

import Dao.OrderDao;
import interfac.OrderOperation;
import pojo.MilkTeaProduct;
import pojo.Order;

import java.util.List;
import java.util.Scanner;

public class ShowOrdersOperation implements OrderOperation {
    @Override
    public void execute(Scanner scanner) {
        OrderDao orderDao = new OrderDao();
        List<Order> orders = orderDao.getOrders();
        System.out.println("订单列表如下：");
        for (Order order : orders) {
            System.out.println("订单编号: " + order.getOrder_id());
            System.out.println("订单状态: " + order.getOrder_status());
            System.out.println("订单总金额: " + order.getTotal_amount());
            System.out.println("包含的奶茶产品及数量:");
            List<MilkTeaProduct> products = order.getProducts();
            int[] quantities = order.getQuantities();

            // 检查产品列表和数量数组是否为空或长度不一致
            if (products == null || quantities == null || products.size() != quantities.length) {
                System.out.println("订单异常，无法显示详细信息。");
                continue;
            }
            for (int i = 0; i < products.size(); i++) {
                MilkTeaProduct product = products.get(i);
                int quantity = quantities[i];
                System.out.println(" - " + product.getProduct_name() + " x" + quantity + "，单价：" + product.getPrice());
            }
            System.out.println("下单时间:"+order.getCreated_at());
            System.out.println("----------------------");
        }
    }
}
